﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;
using System.Data.SqlClient;
using System.Text.RegularExpressions;

namespace Defector
{
          /// <summary>
          /// Interaction logic for Stats.xaml
          /// </summary>
          public partial class Stats : Window
          {

                    public SqlConnection con;
                    int total = 0;
                    int open = 0;
                    int closed = 0;
                    int assignedNum = 0;
                    int unassignedNum = 0;
                    int critical = 0;
                    int high = 0;
                    int medium = 0;
                    int lowNum = 0;

                    public Stats()
                    {
                              InitializeComponent();
                    }

                    /*Original idea with DevOpen and DevClosed was to display the number of tickets assinged to developers. Later it was changed to the total amount of open and closed tickets.
                     *Just didn't rename the methods or labels. Sorry for any confusion. Alexandra*/
                    public void DevOpen1()
                    {
                              con.Open();
                              SqlCommand cmd = new SqlCommand("SELECT COUNT(dbo.Trouble_Report.Trouble_Report_ID) FROM dbo.Trouble_Report WHERE dbo.Trouble_Report.Status = 'true' ", con);
                              cmd.CommandType = CommandType.Text;
                              SqlDataReader sqlReader = cmd.ExecuteReader();
                              while(sqlReader.Read())
                              {
                                  open = Convert.ToInt32(sqlReader[0].ToString());
                                  DevOpen.Content = open;
                               
                              }
                              con.Close();
                    }

                    public void DevClosed1()
                    {
                        con.Open();
                        SqlCommand cmd = new SqlCommand("SELECT COUNT(dbo.Trouble_Report.Trouble_Report_ID) FROM dbo.Trouble_Report WHERE dbo.Trouble_Report.Status = 0 ", con);
                        cmd.CommandType = CommandType.Text;
                        SqlDataReader sqlReader = cmd.ExecuteReader();
                        while (sqlReader.Read())
                        {
                            closed = Convert.ToInt32(sqlReader[0].ToString());
                            DevClosed.Content = closed;

                        }
                        con.Close();
                    }

                    /*DevTotal is really the total number of active trouble reports*/
                    public void DevTotal1()
                    {
                        con.Open();
                        SqlCommand cmd = new SqlCommand("SELECT COUNT(dbo.Trouble_Report.Trouble_Report_ID) FROM dbo.Trouble_Report ", con);
                        cmd.CommandType = CommandType.Text;
                        SqlDataReader sqlReader = cmd.ExecuteReader();
                        while (sqlReader.Read())
                        {
                            total = Convert.ToInt32(sqlReader[0].ToString());
                            DevTotal.Content = total;

                        }
                        con.Close();
                    }

                    /*All of the following code is pretty much just using a sql statement to retrieve a count from the database and excuting and chaging the label on the GUI to the that number*/

                    public void Assigned()
                    {
                        con.Open();
                        SqlCommand cmd = new SqlCommand("SELECT COUNT(dbo.Trouble_Report.Trouble_Report_ID) FROM dbo.Trouble_Report WHERE dbo.Trouble_Report.Status = 'true' ", con);
                        cmd.CommandType = CommandType.Text;
                        SqlDataReader sqlReader = cmd.ExecuteReader();
                        while (sqlReader.Read())
                        {
                            assignedNum = Convert.ToInt32(sqlReader[0].ToString());
                            assigned.Content = assignedNum;

                        }
                        con.Close();
                    }

                    public void UnAssigned()
                    {
                        con.Open();
                        SqlCommand cmd = new SqlCommand("SELECT COUNT(dbo.Trouble_Report.Trouble_Report_ID) FROM dbo.Trouble_Report WHERE dbo.Trouble_Report.Status = 'false' ", con);
                        cmd.CommandType = CommandType.Text;
                        SqlDataReader sqlReader = cmd.ExecuteReader();
                        while (sqlReader.Read())
                        {
                            
                            unassigned.Content = Convert.ToInt32(sqlReader[0].ToString());

                        }
                        con.Close();
                    }

                    public void New()
                    {                                       
                        con.Open();
                        SqlCommand cmd = new SqlCommand("SELECT COUNT(dbo.Trouble_Report.Trouble_Report_ID) FROM dbo.Trouble_Report WHERE dbo.Trouble_Report.Status IS NULL ", con);
                        cmd.CommandType = CommandType.Text;
                        SqlDataReader sqlReader = cmd.ExecuteReader();
                        while (sqlReader.Read())
                        {
                            unassignedNum = Convert.ToInt32(sqlReader[0].ToString());
                            new1.Content = unassignedNum;

                        }
                        con.Close();
                    }


                    public void isCritical()
                    {


                              con.Open();
                              SqlCommand cmd = new SqlCommand("SELECT COUNT(dbo.Trouble_Report.Trouble_Report_ID) FROM dbo.Trouble_Report WHERE dbo.Trouble_Report.Priority = 'Critical' AND dbo.Trouble_Report.Status IS NULL OR dbo.Trouble_Report.Status = 0", con);
                              cmd.CommandType = CommandType.Text;
                              SqlDataReader sqlReader = cmd.ExecuteReader();
                              while (sqlReader.Read())
                              {
                                  critical = Convert.ToInt32(sqlReader[0].ToString());      
                                  Critical.Content = critical;

                              }
                              con.Close();
                    }



                    public void isHigh()
                    {

                           

                              con.Open();
                              SqlCommand cmd = new SqlCommand("SELECT COUNT(dbo.Trouble_Report.Trouble_Report_ID) FROM dbo.Trouble_Report WHERE dbo.Trouble_Report.Priority = 'High' AND dbo.Trouble_Report.Status IS NULL OR dbo.Trouble_Report.Status = 0", con);
                              cmd.CommandType = CommandType.Text;
                              SqlDataReader sqlReader = cmd.ExecuteReader();
                              while (sqlReader.Read())
                              {
                                  high = Convert.ToInt32(sqlReader[0].ToString());      
                                  High.Content = high;

                              }
                              con.Close();
                    }

                    public void isMed()
                    {


                              con.Open();
                              SqlCommand cmd = new SqlCommand("SELECT COUNT(dbo.Trouble_Report.Trouble_Report_ID) FROM dbo.Trouble_Report WHERE dbo.Trouble_Report.Priority = 'Medium' AND dbo.Trouble_Report.Status IS NULL OR dbo.Trouble_Report.Status = 0", con);
                              cmd.CommandType = CommandType.Text;
                              SqlDataReader sqlReader = cmd.ExecuteReader();
                              while (sqlReader.Read())
                              {
                                  medium = Convert.ToInt32(sqlReader[0].ToString());       
                                  med.Content = medium;

                              }
                              con.Close();
                    }

                    public void islow()
                    {

                              

                              con.Open();
                              SqlCommand cmd = new SqlCommand("SELECT COUNT(dbo.Trouble_Report.Trouble_Report_ID) FROM dbo.Trouble_Report WHERE dbo.Trouble_Report.Priority = 'Low' AND dbo.Trouble_Report.Status IS NULL OR dbo.Trouble_Report.Status = 0 ", con);
                              cmd.CommandType = CommandType.Text;
                              SqlDataReader sqlReader = cmd.ExecuteReader();
                              while (sqlReader.Read())
                              {
                                  lowNum = Convert.ToInt32(sqlReader[0].ToString());      
                                  low.Content = lowNum;

                              }
                              con.Close();
                    }

                    private void btnGraphs_Click(object sender, RoutedEventArgs e)
                    {
                        Graphs graphWindow = new Graphs(total, assignedNum, unassignedNum, open, closed, critical, high, medium, lowNum);
                        graphWindow.Show();
                    }





                 /*  
                  * Also added some stuff to the database for the tester table and still no luck. Will try to finish this tomorrow(later today). As in the 4.27.11 Alexandra
                  * 
                  * public void TesterOpen1()
                    {
                        con.Open();
                        SqlCommand cmd = new SqlCommand("SELECT COUNT(dbo.Trouble_Report.Trouble_Report_ID) FROM dbo.Trouble_Report WHERE dbo.People_Tester.Id = dbo.Trouble_Report.PersonId", con);
                        cmd.CommandType = CommandType.Text;
                       SqlDataReader sqlReader = cmd.ExecuteReader();
                        while (sqlReader.Read())
                        {
                            TesterOpen.Content = sqlReader[0].ToString();

                       }
                        con.Close();
                    }

                    public void TesterClosed1()
                    {
                        con.Open();
                        SqlCommand cmd = new SqlCommand("SELECT COUNT(dbo.Trouble_Report.Trouble_Report_ID) FROM dbo.Trouble_Report dbo.Trouble_Report.Date_Completed != null' ", con);
                        cmd.CommandType = CommandType.Text;
                        SqlDataReader sqlReader = cmd.ExecuteReader();
                        while (sqlReader.Read())
                        {
                            TesterClosed.Content = sqlReader[0].ToString();

                        }
                        con.Close();
                    }

                    public void TesterTotal1()
                    {
                        con.Open();
                        SqlCommand cmd = new SqlCommand("SELECT COUNT(dbo.Trouble_Report.Trouble_Report_ID) FROM dbo.Trouble_Report ", con);
                        cmd.CommandType = CommandType.Text;
                        SqlDataReader sqlReader = cmd.ExecuteReader();
                        while (sqlReader.Read())
                        {
                            TesterTotal.Content = sqlReader[0].ToString();

                        }
                        con.Close();
                    }*/
          }
}
